<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>反射</title>
</head>
<body>
    <script>
        // const obj = {
        //     name:"cq",
        //     age:18,
        //     height:1.90
        // }
        // Reflect.defineProperty(obj,"name",{
        //     configurable:false,
        //     enumerable:true
        // })
        // delete obj.name;
        // console.log(obj.name);
           const obj = {
            name:"cq",
            age:18,
            height:1.90
        }
        
        let newProxy = new Proxy(obj,{
            set:function (target,key,newValue)
            {
                 let flag =  Reflect.set(target,key,newValue);
                 if(flag)
                 {
                      console.log(`给对象${target.name}设置新值${newValue}`);
                 }
                 else
                 {
                    console.log("设置新值失败");
                 }
            },
            get:function(target,key,receiver)
            {
                console.log("获取值");
                return Reflect.get(target,key,receiver);
            }
        })

        newProxy.age = 123;
        console.log(newProxy.age);
    </script>
</body>
</html>